﻿using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Globalization;

namespace AllenHung.FeedReader
{
    [Table]
    public class FeedSource : INotifyPropertyChanged, INotifyPropertyChanging
    {
        private int _SourceId;
        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int SourceId
        {
            get { return _SourceId; }
            set
            {
                if (_SourceId != value)
                {
                    NotifyPropertyChanging("SourceId");
                    _SourceId = value;
                    NotifyPropertyChanged("SourceId");
                }
            }
        }

        private string _SourceName;
        [Column]
        public string SourceName
        {
            get { return _SourceName; }
            set
            {
                if (_SourceName != value)
                {
                    NotifyPropertyChanging("SourceName");
                    _SourceName = value;
                    NotifyPropertyChanged("SourceName");
                }
            }
        }

        private string _SourceImagePath;
        [Column]
        public string SourceImagePath
        {
            get { return _SourceImagePath; }
            set
            {
                if (_SourceImagePath != value)
                {
                    NotifyPropertyChanging("SourceImagePath");
                    _SourceImagePath = value;
                    NotifyPropertyChanged("SourceImagePath");
                }
            }
        }

        private string _SourceUri;
        [Column]
        public string SourceUri
        {
            get { return _SourceUri; }
            set
            {
                if (_SourceUri != value)
                {
                    NotifyPropertyChanging("SourceUri");
                    _SourceUri = value;
                    NotifyPropertyChanged("SourceUri");
                }
            }
        }

        private bool _IsSubscribed;
        [Column]
        public bool IsSubscribed
        {
            get { return _IsSubscribed; }
            set
            {
                if (_IsSubscribed != value)
                {
                    NotifyPropertyChanging("IsSubscribed");
                    _IsSubscribed = value;
                    NotifyPropertyChanged("IsSubscribed");
                }
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        // Used to notify that a property changed
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region INotifyPropertyChanging Members

        public event PropertyChangingEventHandler PropertyChanging;

        // Used to notify that a property is about to change
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        #endregion
    }
}
